﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KhaoSatSinhVienTotNghiep.Model
{
   public partial class DotKhaoSat
    {

       private static KhaoSatSVTNDataContext context = new KhaoSatSVTNDataContext();
       public static List<DotKhaoSat> GetAllDotKhaoSat()
       {
           return context.DotKhaoSats.ToList();
       }

       public static bool AddNew(string tenDotKS)
       {
           if (CheckExist(tenDotKS) == false)
           {
               DotKhaoSat dks = new DotKhaoSat { TenDotKS = tenDotKS.Trim() };
               context.DotKhaoSats.InsertOnSubmit(dks);
               context.SubmitChanges();
               return true;
           }
           else return true;
       }

       public static DotKhaoSat GetDotKSByName(string tenDotKS)
       {
           return context.DotKhaoSats.Where(dks => dks.TenDotKS.CompareTo(tenDotKS.Trim()) == 0).FirstOrDefault();
       }
       public static DotKhaoSat GetDotKSByID(int id)
       {
           return context.DotKhaoSats.Where(dks => dks.MaDotKS==id).FirstOrDefault();
       }
       public static bool CheckExist(string tenDotKS)
       {
           var result= context.DotKhaoSats.Where(dks => dks.TenDotKS.CompareTo(tenDotKS.Trim()) == 0).FirstOrDefault();
           if (result != null)
               return true;
           else return false;
       }
    }
}
